#include<stdio.h>

int main(void)
{
    int N;
    
    while (scanf("%d",&N) != EOF)
    {   
        int one = 0;
        for (int j = 1; j <= N; j++)
        {
            for (int i = 1; j/i >= 1; i *= 10)
            {
                if ((j/i)%10 == 1 || (j/i)%10 == 2)
                {
                    one++;
                }   
            }
        }
        printf("%d\n",one);
    }
}